/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package reamodel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

import reamodel.EconomicResource;
import reamodel.EconomicResourceType;
import reamodel.Inflow;
import reamodel.Outflow;
import reamodel.ReamodelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Economic Resource</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link reamodel.impl.EconomicResourceImpl#getInflow <em>Inflow</em>}</li>
 *   <li>{@link reamodel.impl.EconomicResourceImpl#getOutflow <em>Outflow</em>}</li>
 *   <li>{@link reamodel.impl.EconomicResourceImpl#getName <em>Name</em>}</li>
 *   <li>{@link reamodel.impl.EconomicResourceImpl#getTypifiedBy <em>Typified By</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EconomicResourceImpl extends EObjectImpl implements EconomicResource {
	/**
	 * The cached value of the '{@link #getInflow() <em>Inflow</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInflow()
	 * @generated
	 * @ordered
	 */
	protected EList<Inflow> inflow;

	/**
	 * The cached value of the '{@link #getOutflow() <em>Outflow</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOutflow()
	 * @generated
	 * @ordered
	 */
	protected EList<Outflow> outflow;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getTypifiedBy() <em>Typified By</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypifiedBy()
	 * @generated
	 * @ordered
	 */
	protected EconomicResourceType typifiedBy;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EconomicResourceImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ReamodelPackage.Literals.ECONOMIC_RESOURCE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Inflow> getInflow() {
		if (inflow == null) {
			inflow = new EObjectWithInverseResolvingEList<Inflow>(Inflow.class, this, ReamodelPackage.ECONOMIC_RESOURCE__INFLOW, ReamodelPackage.INFLOW__RESOURCE);
		}
		return inflow;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Outflow> getOutflow() {
		if (outflow == null) {
			outflow = new EObjectWithInverseResolvingEList<Outflow>(Outflow.class, this, ReamodelPackage.ECONOMIC_RESOURCE__OUTFLOW, ReamodelPackage.OUTFLOW__RESOURCE);
		}
		return outflow;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ReamodelPackage.ECONOMIC_RESOURCE__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EconomicResourceType getTypifiedBy() {
		if (typifiedBy != null && typifiedBy.eIsProxy()) {
			InternalEObject oldTypifiedBy = (InternalEObject)typifiedBy;
			typifiedBy = (EconomicResourceType)eResolveProxy(oldTypifiedBy);
			if (typifiedBy != oldTypifiedBy) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, ReamodelPackage.ECONOMIC_RESOURCE__TYPIFIED_BY, oldTypifiedBy, typifiedBy));
			}
		}
		return typifiedBy;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EconomicResourceType basicGetTypifiedBy() {
		return typifiedBy;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTypifiedBy(EconomicResourceType newTypifiedBy, NotificationChain msgs) {
		EconomicResourceType oldTypifiedBy = typifiedBy;
		typifiedBy = newTypifiedBy;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ReamodelPackage.ECONOMIC_RESOURCE__TYPIFIED_BY, oldTypifiedBy, newTypifiedBy);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTypifiedBy(EconomicResourceType newTypifiedBy) {
		if (newTypifiedBy != typifiedBy) {
			NotificationChain msgs = null;
			if (typifiedBy != null)
				msgs = ((InternalEObject)typifiedBy).eInverseRemove(this, ReamodelPackage.ECONOMIC_RESOURCE_TYPE__TYPIFY, EconomicResourceType.class, msgs);
			if (newTypifiedBy != null)
				msgs = ((InternalEObject)newTypifiedBy).eInverseAdd(this, ReamodelPackage.ECONOMIC_RESOURCE_TYPE__TYPIFY, EconomicResourceType.class, msgs);
			msgs = basicSetTypifiedBy(newTypifiedBy, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ReamodelPackage.ECONOMIC_RESOURCE__TYPIFIED_BY, newTypifiedBy, newTypifiedBy));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ReamodelPackage.ECONOMIC_RESOURCE__INFLOW:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getInflow()).basicAdd(otherEnd, msgs);
			case ReamodelPackage.ECONOMIC_RESOURCE__OUTFLOW:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getOutflow()).basicAdd(otherEnd, msgs);
			case ReamodelPackage.ECONOMIC_RESOURCE__TYPIFIED_BY:
				if (typifiedBy != null)
					msgs = ((InternalEObject)typifiedBy).eInverseRemove(this, ReamodelPackage.ECONOMIC_RESOURCE_TYPE__TYPIFY, EconomicResourceType.class, msgs);
				return basicSetTypifiedBy((EconomicResourceType)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ReamodelPackage.ECONOMIC_RESOURCE__INFLOW:
				return ((InternalEList<?>)getInflow()).basicRemove(otherEnd, msgs);
			case ReamodelPackage.ECONOMIC_RESOURCE__OUTFLOW:
				return ((InternalEList<?>)getOutflow()).basicRemove(otherEnd, msgs);
			case ReamodelPackage.ECONOMIC_RESOURCE__TYPIFIED_BY:
				return basicSetTypifiedBy(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ReamodelPackage.ECONOMIC_RESOURCE__INFLOW:
				return getInflow();
			case ReamodelPackage.ECONOMIC_RESOURCE__OUTFLOW:
				return getOutflow();
			case ReamodelPackage.ECONOMIC_RESOURCE__NAME:
				return getName();
			case ReamodelPackage.ECONOMIC_RESOURCE__TYPIFIED_BY:
				if (resolve) return getTypifiedBy();
				return basicGetTypifiedBy();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ReamodelPackage.ECONOMIC_RESOURCE__INFLOW:
				getInflow().clear();
				getInflow().addAll((Collection<? extends Inflow>)newValue);
				return;
			case ReamodelPackage.ECONOMIC_RESOURCE__OUTFLOW:
				getOutflow().clear();
				getOutflow().addAll((Collection<? extends Outflow>)newValue);
				return;
			case ReamodelPackage.ECONOMIC_RESOURCE__NAME:
				setName((String)newValue);
				return;
			case ReamodelPackage.ECONOMIC_RESOURCE__TYPIFIED_BY:
				setTypifiedBy((EconomicResourceType)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ReamodelPackage.ECONOMIC_RESOURCE__INFLOW:
				getInflow().clear();
				return;
			case ReamodelPackage.ECONOMIC_RESOURCE__OUTFLOW:
				getOutflow().clear();
				return;
			case ReamodelPackage.ECONOMIC_RESOURCE__NAME:
				setName(NAME_EDEFAULT);
				return;
			case ReamodelPackage.ECONOMIC_RESOURCE__TYPIFIED_BY:
				setTypifiedBy((EconomicResourceType)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ReamodelPackage.ECONOMIC_RESOURCE__INFLOW:
				return inflow != null && !inflow.isEmpty();
			case ReamodelPackage.ECONOMIC_RESOURCE__OUTFLOW:
				return outflow != null && !outflow.isEmpty();
			case ReamodelPackage.ECONOMIC_RESOURCE__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case ReamodelPackage.ECONOMIC_RESOURCE__TYPIFIED_BY:
				return typifiedBy != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //EconomicResourceImpl
